<?php
namespace app\shop\controller;
use app\AdminRest;
use app\shop\model\StoreCompany;
use think\App;
use app\shop\model\AdminStore as CouponModel;

use think\facade\Db;

class AdminStore extends AdminRest
{

    protected $model;


    public function __construct(App $app) {

        parent::__construct($app);

        $this->model      = new CouponModel();

    }


    /**
     * @author chenniang
     * @DataTime: 2020-06-22 09:34
     * @功能说明:自提点列表
     */
    public function storeList(){

        $input = $this->_param;

        $dis[] = ['uniacid','=',$this->_uniacid];
        //未删除
        $dis[] = ['status','>',-1];

        $where = [];

        if(!empty($input['title'])){
            //名字搜索
            $where[] = ['title','like','%'.$input['title'].'%'];
            //地址搜索
            $where[] = ['address','like','%'.$input['title'].'%'];
        }

        $data = $this->model->storeList($dis,$where,$input['limit']);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-06-22 09:43
     * @功能说明:添加自提点
     */
    public function storeAdd(){

        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $input = $this->model->changeData($input);

        $res = $this->model->storeAddAdmin($input);

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-06-22 09:43
     * @功能说明:修改自提点
     */
    public function storeUpdate(){

        $input = $this->_input;

        $dis['id'] = $input['id'];

        $input = $this->model->changeData($input);

        $res = $this->model->storeUpdateAdmin($dis,$input);

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-06-22 09:45
     * @功能说明:自提点详情
     */
    public function storeInfo(){

        $input = $this->_param;

        $dis['id'] = $input['id'];

        $res = $this->model->storeInfo($dis);

        $dis = [

            'a.store_id' => $input['id'],

            'a.uniacid'=> $this->_uniacid
        ];

        $store_company_model = new StoreCompany();

        $res['company'] = $store_company_model->getId($dis);

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-06-22 09:48
     * @功能说明:上下架|删除
     */
    public function statusUpdate(){

        $input = $this->_input;

        $dis['id'] = $input['id'];

        $data['status'] = $input['status'];

        $res = $this->model->storeUpdate($dis,$data);

        return $this->success($res);

    }










}
